interface Messages {
  [key: string]: string
}

interface MessageModule {
  namespace: string
  messages: Messages
}

const req = require.context('./modules', false, /\.ts$/)
const requireAll = (requireContext: any): { default: MessageModule }[] => requireContext.keys().map(requireContext)

const messages: Messages = {}

requireAll(req).forEach(({ default: m }) => {
  if (m.namespace) {
    Object.entries(m.messages || {}).forEach(([key, defaultValue]) => {
      messages[`${m.namespace}_${key}`] = defaultValue
    })
  }
})

export { messages }
